import { Component, OnInit } from '@angular/core';
import { parts, optionCarType, wayOptionOrderStatus, otherOptionPayStatus} from '../HuoCustmp.model';
import { ApiService } from '../../../../providers/ApiPro.service';

@Component({
  selector: 'app-HuoCusWaybill',
  templateUrl: './HuoCusWaybill.component.html',
  styleUrls: ['./HuoCusWaybill.component.scss']
})
export class HuoCusWaybillComponent implements OnInit {
  public optionCarType = optionCarType;
  public optionOrderStatus = wayOptionOrderStatus;
  public optionPayStatus = otherOptionPayStatus;
  public _total = 0;
  public pageIndex = 1;
  public parts: parts = new parts();
  public data = [];
  public once = true
  public deliverTime:string = null;
  constructor(
    private apiService: ApiService,
  ) { }

  ngOnInit() {
    this.loadAll();
  }

   loadAll(){
    let url = "findtransportorder";
    if(this.deliverTime){
      this.parts.deliverTime=this.apiService.formatDateTime2(this.deliverTime);
    }else if(!this.deliverTime){
      delete this.parts.deliverTime;
    }
    if(!this.parts.orderStatus){
      delete this.parts.orderStatus;    
    }
    if(!this.parts.carType){
      delete this.parts.carType;    
    }
    if(!this.parts.payStatus){
      delete this.parts.payStatus;
    }
    this.apiService.get(url,this.parts)
      .then(res =>{
        this._total = res.totalCount;
        this.data = res.result;
      })
  }

  resetIndex(e) {
        this.parts.setPage(e);
        this.loadAll();
  }

}
